package com.itheima79.googleplay.ui.fragment;

import java.util.ArrayList;
import java.util.List;

import com.google.gson.reflect.TypeToken;
import com.itheima79.googleplay.adapter.BasicAdapter;
import com.itheima79.googleplay.adapter.HomeAdapter;
import com.itheima79.googleplay.bean.AppInfo;
import com.itheima79.googleplay.http.Api;
import com.itheima79.googleplay.http.HttpUtil;
import com.itheima79.googleplay.util.CommonUtil;
import com.itheima79.googleplay.util.JsonUtil;

public class AppFragment extends BaseListFragment<AppInfo> {
	@Override
	protected BasicAdapter<AppInfo> getAdapter() {
		return new HomeAdapter(list);
	}

	@Override
	protected Object requestData() {
		String result = HttpUtil.get(Api.App+list.size());
		ArrayList<AppInfo> appInfos = (ArrayList<AppInfo>) JsonUtil.parseJsonToList(result,new TypeToken<List<AppInfo>>(){}.getType());
		
		if(appInfos!=null){
			list.addAll(appInfos);//更新数据
			
			CommonUtil.runOnUIThread(new Runnable() {
				@Override
				public void run() {
					//更新UI
					adapter.notifyDataSetChanged();
					//完成刷新
					refreshListView.onRefreshComplete();
				}
			});
		}
		return appInfos;
	}

	
}
